<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  //提取Email地址
  var str = '12345656712@163.com fswef siahochuang@qq.com terdgre ochuang@qq.com'
  //小括号是优先级，每个代表一个规则
  var array = str.match(/\w+@[a-z0-9A-Z]+.\w+/g);
  var array1 = str.match(/^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/g);
  var reg = /\w+@[a-z0-9A-Z]+.\w+/g
  var array2 = reg.exec(str)
  //^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$
  console.log(array);
  console.log(array1);
  console.log(array2);
  //$代表第几个规则
  console.log(RegExp.$1)
  var str1 = 'adad .ad adfega.d'
  //str1.replace也支持正则替换  第一个参数可以是String类型或者RegExp
  var str2 = str1.replace(/a/g, 'z')
  console.log(str2);
</script>

</html>